<?php

class Session {
	private $_vars;
	private static $_instance;
	/**
	 * Enter description here...
	 *
	 * @return Session
	 */
	public static function instance(){
		if(self::$_instance==null){
			self::$_instance = new Session();
		}
		return self::$_instance;
	}
	private function __construct(){
		if(!session_start()){
			throw new Exception("Session not started ");
		}
		$this->_vars = $_SESSION;
		foreach ($_SESSION as $key=>$value){
			unset($_SESSION[$key]);
		}
		//var_dump($this->_vars);
	}
	
	public function __get($name){
		if(!isset($this->_vars[$name])){
			throw new NullPointerException();
		}
		return $this->_vars[$name];
	}
	
	public function __set($name,$value){
		$this->_vars[$name] = $value;
	}
	
	public function __destruct(){
		$_SESSION=$this->_vars;
		foreach ($this->_vars as $var=>$value){
			$_SESSION[$var] = $value;
		}
		//var_dump($_SESSION);
		//session_register(serialize($this->_vars));
		//session_write_close();
	}
}

?>